package com.xxx.baseapplication.adapter

import androidx.lifecycle.MutableLiveData
import com.xxx.baseapplication.R
import com.xxx.baseapplication.databinding.ItemProjectCategoryBinding
import com.xxx.baseapplication.vo.ProjectCategoryVO
import com.xxx.mylibrary.base.DataBoundAdapter

class ProjectCategoryAdapter(var selectItem: MutableLiveData<ProjectCategoryVO>) :
    DataBoundAdapter<ProjectCategoryVO, ItemProjectCategoryBinding>() {

    override fun initView(
        binding: ItemProjectCategoryBinding,
        item: ProjectCategoryVO
    ) {
        binding.vo = item
        binding.root.setOnClickListener {
            updateSelectItem(item)
        }
    }

    fun updateSelectItem(item: ProjectCategoryVO) {
        mData.forEach { it.select = false }
        item.select = true
        notifyDataSetChanged()
        selectItem.value = item
    }

    override val layoutId: Int
        get() = R.layout.item_project_category
}